package com.dz.Controller;

import com.dz.domain.emp;
import com.dz.domain.user;
import com.dz.userService.impl.EmpServiceImpl;
import com.dz.userService.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.server.Session;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

@CrossOrigin
@RestController
public class testVueIntface {

    @Autowired
    UserServiceImpl uService;

    @PostMapping("/testEmp")
    public boolean testEmp(@RequestBody emp e){
        int row = uService.insertUser(e);
        boolean flag = false;
        if (row == 1){
            return !flag;
        }else{
            return flag;
        }
    }

    /**
     *
     * vue-element系统登入接口
     *
     * */
    @RequestMapping("/LoginSys")
    public boolean testLoginSys(@RequestBody user userInf, HttpServletRequest request){
        boolean flag = uService.findLoginSys(userInf);
        if (flag == true){
            request.getSession().setAttribute("admin", userInf.getLoginname());
            return true;
        }else{
            return false;
        }
    }

    /**
     * 查询所有用户
     * */
    @ResponseBody
    @RequestMapping("/findAll")
    public List<emp> findAll(HttpServletRequest request){
        System.out.println("controller方法"+ request.getSession().getAttribute("admin"));

        System.out.println("findAll");
        List<emp> listEmp = uService.findTestVueAll();
        return listEmp;
    }

    @ResponseBody
    @PostMapping("/testDemo")
    public void testDemo(@RequestBody Date date, HttpServletRequest request){
        System.out.println(date);
    }
}
